      *> File Name     000005_UserDefinedStruct.cbl.
      *> Description   Defining and using a Micro Focus COBOL ValueType,
      *>               i.e., a .NET struct.
      *> Project Type  Console Application.
      *> CodePlex URL  http://cobol.codeplex.com
 
       program-id.   Main.
       repository.
           class point        as "Point"
           class sys-console  as "System.Console"
           class sys-env      as "System.Environment"
           .
       working-storage section.
       01  newline  string  value sys-env::"NewLine".
       01  p1       point.
       01  p2       point.
       procedure division.
           move "Defining and Using a ValueType, i.e., a Struct"
               to sys-console::"Title"
 
           if type of point::"IsValueType" then
               display type of point " is a value type." newline
           else
               display type of point " is a reference type." newline
           end-if
 
           move point::"New"(10, 20) to p1
           move p1 to p2 *> assignment of value types creates a copy
 
           display "p1: " p1
           display "p2: " p2 newline
           
           invoke p2::"Offset"(10, 10)
 
           display "p1: " p1
           display "p2: " p2 newline
           
           display "p2.X: " p2::"X"
           display "p2.Y: " p2::"Y" newline
 
           display "Press any key to continue . . . "
           invoke sys-console::"ReadKey"(true)
           .
       end program   Main.
 
       valuetype-id. Point.
       repository.
           property X
           property Y
           .
       working-storage section.
       01  _x  binary-long.
       01  _y  binary-long.
      *>
       method-id.    New.
       linkage section.
       01  x  binary-long.
       01  y  binary-long.
       procedure division using x, y.
           move x to _x
           move y to _y
           .
       end method    New.
      *>
       method-id.    get property X.
       procedure division giving x as binary-long.
           move _x to x
           .
       end method.
      *>
       method-id.    get property Y.
       procedure division giving y as binary-long.
           move _y to y
           .
       end method.
      *>
       method-id.    Offset.
       linkage section.
       01  dx   binary-long.
       01  dy   binary-long.
       procedure division using by value dx, dy.
           add dx to _x
           add dy to _y
           .       
       end method    Offset.
      *>
       method-id.    ToString override.
       procedure division giving s as string.
           move string::"Concat"("{X=", _x, ",Y=", _y, "}") to s
           .
       end method    ToString.
      *>
       end valuetype Point.